package com.pay.plat.controller;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.pay.entity.BankType;
import com.pay.entity.CashDetails;
import com.pay.plat.annotation.AuthResource;
import com.pay.plat.mapping.MappingUtils;
import com.pay.service.IBankTypeService;
import com.pay.service.ICashDetailsService;
import com.pay.utils.BasePage;
import com.pay.utils.ResponseData;

@Controller
public class FinanceController {
	
	@Autowired
	private ICashDetailsService cashDetailsService ;
	
	@Autowired
	private IBankTypeService bankTypeService ;
	
	@AuthResource
	@RequestMapping(value=MappingUtils.showCashDetailList)
	public ModelAndView showCashDetailList(CashDetails cashDetails,BasePage<CashDetails> page,Integer loginId) {
		cashDetailsService.getList(cashDetails, page);
		ModelAndView m = new ModelAndView(MappingUtils.showCashDetailList);
		m.addObject("cashDetails", cashDetails) ;
		m.addObject("loginId", loginId) ;
		m.addObject("list", page) ;
		return m ;
	}
	
	@AuthResource
	@ResponseBody
	@RequestMapping(value=MappingUtils.doCashPreper)
	public ResponseData doCashPreper(Integer id,Integer status) {
		return cashDetailsService.doCashPreper(id,status) ;
	}
	
	@AuthResource
	@RequestMapping(value=MappingUtils.showBankTypeList)
	public ModelAndView showBankTypeList(BankType bankType,BasePage<BankType> page,Integer loginId) {
		bankTypeService.getList(bankType,page) ;
		ModelAndView m = new ModelAndView(MappingUtils.showBankTypeList);
		m.addObject("bankType", bankType) ;
		m.addObject("loginId", loginId) ;
		m.addObject("list", page) ;
		return m ;
	}
	
	
	@AuthResource
	@RequestMapping(value=MappingUtils.showBankTypeAdd)
	public ModelAndView showBankTypeAdd(Integer loginId) {
		ModelAndView m = new ModelAndView(MappingUtils.showBankTypeAdd);
		m.addObject("loginId", loginId) ;
		return m ;
	}
	
	@AuthResource(url=MappingUtils.showBankTypeAdd)
	@ResponseBody
	@RequestMapping(value=MappingUtils.doBankTypeAdd,method= {RequestMethod.POST})
	public ResponseData doBankTypeAdd(BankType bankType) throws IOException {
		return bankTypeService.doBankTypeAdd(bankType) ;
	}
	
	@AuthResource
	@RequestMapping(value=MappingUtils.showBankTypeEdit)
	public ModelAndView showBankTypeEdit(Integer id,Integer loginId) {
		BankType bankType = bankTypeService.getById(id);
		ModelAndView m = new ModelAndView(MappingUtils.showBankTypeEdit);
		m.addObject("loginId", loginId) ;
		m.addObject("bankType", bankType) ;
		return m ;
	}
	
	@AuthResource(url=MappingUtils.showBankTypeEdit)
	@ResponseBody
	@RequestMapping(value=MappingUtils.doBankTypeEdit)
	public ResponseData doBankTypeEdit(BankType bankType) {
		return bankTypeService.doBankTypeEdit(bankType) ;
	}
}
